package myfirstgrailsproject

/**
 * This class is a data-holder - this is what
 * we store in the database.
 *
 * @author zach
 *
 */
class Team {
	
	

	String teamName;
	Exercise exercise;
	Course course;

	static constraints = {
		teamName(nullable:false, blank:false);
		exercise(nullable:false, blank:false);
		course(nullable:false, blank:false);
		users(display:false, nullable:true, blank:true);
		//students(display:false, blank:true, nullable:true);
	}

	ArrayList users;
	//These are database relationships
	static hasMany = [users : User];
	static belongsTo = [exercise: Exercise];
	

	String toString(){
		return teamName;
	}
	
	def beforeInsert = {
		def team = Team.findByExerciseAndTeamName(exercise, teamName);
		if (team){
			team.delete(flush:true);
			System.out.println("\n\n\n\n\n\n")
		}
	}


}

